<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 2016/9/23
 * Time: 10:46
 */

/*
 * build the program's capability - define variables and functions...
 */
$item_label = '';        // type string
$item_price = 0.0;       // type float
$item_qty = 1;           // type integer
$item_total = 0.0;       // type float - to set use calculate()

function calculate(){
    global $item_price, $item_qty, $item_total;
    $item_price = number_format($item_price, 2,'.',',');
    $item_total = number_format(($item_price * $item_qty), 2);
}

function itemToString() {
    global $item_label, $item_price, $item_qty, $item_total;
    return "$item_label [price=\$$item_price, qty=$item_qty, total=\$$item_total]";
}

/*
 * run the program - set data, call methods...
 */
$item_label = "Coffee";
$item_price = 3.228;
$item_qty = 2;
calculate();           // set $item_total
echo itemToString();   // -> Coffee [price=$3.89, qty=2, total=$7.78]

$item_label = "Chicken";
$item_price = .80;     // per lb.
$item_qty = 3.5;       // lbs.
calculate();           // set $item_total
echo itemToString();   // -> Chicken [price=$0.80, qty=3.5, total=$2.80]
$ipArr    = explode('.',$_SERVER['REMOTE_ADDR']);
$ip       = $ipArr[0] * 0x1000000
    + $ipArr[1] * 0x10000
    + $ipArr[2] * 0x100
    + $ipArr[3]
;
include_once 'Util.php';
use zrx\Util as test;
test::br('',$ip);
//$ipArr    = explode('.',$_SERVER['REMOTE_ADDR']);
$ip       = $ipArr[0]<<24
    + $ipArr[1]<<16
    + $ipArr[2] <<8
    + $ipArr[3];
test::br('',$ip);

$files = [];
$handle = opendir('.');
while (false !== ($file = readdir($handle))) {
    $files[] = $file;
}
closedir($handle);

test::br('',$files);

$fieldmap = array
(
    'id', 'import_id',
    'productname', 'title',
    'datetime_online', 'onlineDate',
    'datetime_test_final', 'offlineDate',
    'active', 'status',
    'questionaire_intro', 'text_lead',
    'datetime_online', 'createdAt',
    'datetime_online', 'updatedAt'
);

while(list(,$key) = each($fieldmap))
{
    list(,$value) = each($fieldmap);
    echo "$key: $value\n";
}
